/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package action.organization;

import com.opensymphony.xwork2.ActionSupport;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import myUtils.Constants;
import myUtils.page.Result;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.SessionAware;
import po.Organization;
import service.OrgService;

/**
 *
 * @author luyang
 */
public class GetCheckedOrgAction extends ActionSupport implements ServletRequestAware,SessionAware
{
    private HttpServletRequest request;
    private OrgService orgService;
    private Map session;

    @Override
    public String execute()
    {
        //String msg=""
        Result result=orgService.getCheckedOrg(request.getParameter("page")==null?1:Integer.parseInt((String) request.getParameter("page")));

        if(session.get("right")==null)
            session.put("right",String.valueOf(Constants.USER ));
        if(session.get("status")==null)
            session.put("status", String.valueOf(Constants.GUEST));

        List list=result.getContent();
        Iterator it=list.listIterator();
        while(it.hasNext())
        {
            Organization org=(Organization)it.next();
            org.setDescription(myUtils.Utils.getSubstring(org.getDescription()));
            System.out.println(org.getName());
        }
        System.out.println("current page = "+result.getPage().getCurrentPage());

        request.setAttribute("result", result);

        return SUCCESS;
    }

    public void setOrgService(OrgService orgService)
    {
        this.orgService=orgService;
    }

    public void setServletRequest(HttpServletRequest request)
    {
        this.request=request;
    }

    public void setSession(Map session)
    {
        this.session=session;
    }


}
